package com.lulufind.lulu.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.lulufind.lulu.model.Result;
import com.lulufind.lulu.model.Sticker;
import com.lulufind.lulu.model.Wish;
import com.lulufind.lulu.service.StickerService;
import com.lulufind.lulu.service.WishService;
import com.lulufind.lulu.vo.WishInfoVO;
import com.lulufind.lulu.vo.WishMateVO;

@Controller
@RequestMapping("/wish")
public class WishController {
	
	@Autowired
	WishService wishService;
	@Autowired
	StickerService stickerService;
	
	@ResponseBody
	@RequestMapping(value="/addWish",produces="application/json;charset=UTF-8")
	public String addWish(Wish wish, String userToken, int[] stickerId){
		
		Result<Wish> rs = wishService.addWish(wish, userToken, stickerId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getTypeStickers",produces="application/json;charset=UTF-8")
	public String getTypeStickers(Integer stickerType){
		
		if(stickerType == null){
			stickerType = 0;
		}
		
		Result<List<Sticker>> rs = stickerService.getTypeStickers(stickerType);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAllStickers",produces="application/json;charset=UTF-8")
	public String getAllStickers(){
		
		Result<Map<String,List<Sticker>>> rs = stickerService.getAllStickers();
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getWishMate",produces="application/json;charset=UTF-8")
	public String getWishMate(Integer userId, String userToken, Integer wishId){
		
		Result<List<WishMateVO>> rs = wishService.getWishMate(userId, userToken, wishId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getWishInfos",produces="application/json;charset=UTF-8")
	public String getWishInfos(int userId, String userToken){
		
		Result<List<WishInfoVO>> rs = wishService.getWishInfos(userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
}
